﻿package mortal.game.view.copy.escort.renderer
{
    import Message.Public.*;
    import com.gengine.core.frame.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.escort.*;
    import mortal.game.view.copy.escort.vo.*;
    import mortal.mvc.core.*;

    public class EscortCopySelectTaskRenderer extends GCellRenderer
    {
        private var _bg:GBitmap;
        private var _textTitle:GBitmap;
        private var _textBg:GBitmap;
        private var _todayNum:GTextFiled;
        private var _operBtn:GButton;
        private var _state:GTextFiled;
        private var _award:GTileList;
        private var _secTimer:SecTimer;
        private var _stateStr:String = "";
        private var _isResCompl:Boolean;

        public function EscortCopySelectTaskRenderer()
        {
            return;
        }// end function

        private function onClickOperBtn(event:MouseEvent) : void
        {
            var _loc_3:EscortCopyOperVo = null;
            var _loc_2:* = Cache.instance.copy.escort;
            if (data.type == EscortCopySelectTaskType.ESCORT)
            {
                _loc_3 = new EscortCopyOperVo(EEscortOper._EEscortOperApply);
                _loc_3.extend = _loc_2.hasGetEscortTask ? (EEscortCopySignUp._EEscortCopySignUpNo) : (EEscortCopySignUp._EEscortCopySignUpEscort);
            }
            else
            {
                _loc_3 = new EscortCopyOperVo(EEscortOper._EEscortOperApply);
                _loc_3.extend = _loc_2.hasGetHarryTask ? (EEscortCopySignUp._EEscortCopySignUpNo) : (EEscortCopySignUp._EEscortCopySignUpRob);
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.EscortCopyOper, _loc_3));
            return;
        }// end function

        private function onApplyEscort(param1:Object) : void
        {
            if (data.type == EscortCopySelectTaskType.ESCORT)
            {
                this._operBtn.label = Language.getString(35158);
                this.addSecTimer();
            }
            else
            {
                this._operBtn.label = Language.getString(35159);
                this.killSecTimer();
            }
            return;
        }// end function

        private function onApplyRob(param1:Object) : void
        {
            if (data.type == EscortCopySelectTaskType.HARRY)
            {
                this._operBtn.label = Language.getString(35158);
                this.addSecTimer();
            }
            else
            {
                this._operBtn.label = Language.getString(35160);
                this.killSecTimer();
            }
            return;
        }// end function

        private function onApply(param1:Object) : void
        {
            if (param1 == false)
            {
                this._operBtn.label = data.type == EscortCopySelectTaskType.ESCORT ? (Language.getString(35160)) : (Language.getString(35159));
                this.killSecTimer();
            }
            return;
        }// end function

        private function addSecTimer() : void
        {
            if (!this._secTimer)
            {
                this._secTimer = new SecTimer(1);
            }
            this._secTimer.reset();
            this._secTimer.currentCount = Cache.instance.copy.escort.waittingTime;
            this._secTimer.start();
            this._secTimer.addListener(TimerType.ENTERFRAME, this.onTimeChange);
            this._state.htmlText = Language.getStringByParam(70074, (Cache.instance.copy.escort.waittingTime + 1)) + this._stateStr;
            return;
        }// end function

        private function onTimeChange(param1:SecTimer) : void
        {
            this._state.htmlText = Language.getStringByParam(70074, (param1.currentCount + 1)) + this._stateStr;
            return;
        }// end function

        private function killSecTimer() : void
        {
            if (this._secTimer)
            {
                this._secTimer.stop();
                this._secTimer.dispose();
                this._state.text = "";
                this._secTimer = null;
            }
            return;
        }// end function

        public function updateState() : void
        {
            var _loc_1:* = Cache.instance.copy.escort;
            if (_loc_1.hasGetEscortTask && data.type == EscortCopySelectTaskType.ESCORT)
            {
                this._stateStr = _loc_1.getStateByType(EscortCopySelectTaskType.ESCORT);
            }
            else if (_loc_1.hasGetHarryTask && data.type == EscortCopySelectTaskType.HARRY)
            {
                this._stateStr = _loc_1.getStateByType(EscortCopySelectTaskType.HARRY);
            }
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            var _loc_2:* = Cache.instance.copy.escort;
            if (param1.type == EscortCopySelectTaskType.ESCORT)
            {
                this._todayNum.text = Language.getStringByParam(70059, param1.todayNum);
                this._todayNum.textColor = GlobalStyle.colorLvUint;
                this._state.x = 225;
                this._operBtn.label = Language.getString(35160);
                this._award.dataProvider = new DataProvider(DailyRewardConfig.instance.getRewardByCode(101));
                if (_loc_2.hasGetEscortTask)
                {
                    this._operBtn.label = Language.getString(35158);
                    this.addSecTimer();
                }
            }
            else if (param1.type == EscortCopySelectTaskType.HARRY)
            {
                this._todayNum.text = Language.getStringByParam(70060, param1.todayNum);
                this._todayNum.textColor = GlobalStyle.colorHuangUint;
                this._state.x = -145;
                this._operBtn.label = Language.getString(35159);
                this._award.dataProvider = new DataProvider(DailyRewardConfig.instance.getRewardByCode(102));
                if (_loc_2.hasGetHarryTask)
                {
                    this._operBtn.label = Language.getString(35158);
                    this.addSecTimer();
                }
            }
            this._award.drawNow();
            this.setTextTitle();
            return;
        }// end function

        private function setTextTitle() : void
        {
            return;
        }// end function

        private function onResCompl() : void
        {
            this._isResCompl = true;
            this.setTextTitle();
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.gBitmap("", 0, 20, this);
            this._textTitle = UIFactory.gBitmap("", 83, 13, this);
            this._textBg = UIFactory.gBitmap("", 10, 130, this);
            this._todayNum = UIFactory.gTextField("", 208, 23, 80, 20, this);
            this._operBtn = UIFactory.gButton("", 98, 119, 90, 28, this, "RedButton");
            this._state = UIFactory.gTextField("", 0, 135, 207, 20, this, GlobalStyle.textFormatHuang2.center());
            this._award = UIFactory.tileList(48, 50, 195, 60, this);
            this._award.setStyle("cellRenderer", BgMidItemCellRenderer);
            this._award.selectable = false;
            this._award.columnWidth = 65;
            this._award.rowHeight = 60;
            this._award.direction = GBoxDirection.HORIZONTAL;
            this._operBtn.configEventListener(MouseEvent.CLICK, this.onClickOperBtn);
            NetDispatcher.addCmdListener(ServerCommand.EscortCopyOperApply, this.onApply);
            NetDispatcher.addCmdListener(ServerCommand.EscortApplyEscort, this.onApplyEscort);
            NetDispatcher.addCmdListener(ServerCommand.EscortApplyRob, this.onApplyRob);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            NetDispatcher.removeCmdListener(ServerCommand.EscortApplyEscort, this.onApplyEscort);
            NetDispatcher.removeCmdListener(ServerCommand.EscortApplyRob, this.onApplyRob);
            NetDispatcher.removeCmdListener(ServerCommand.EscortCopyOperApply, this.onApply);
            this.killSecTimer();
            this._bg.dispose(param1);
            this._bg = null;
            this._textTitle.dispose(param1);
            this._textTitle = null;
            this._textBg.dispose(param1);
            this._textBg = null;
            this._todayNum.dispose(param1);
            this._todayNum = null;
            this._award.dispose(param1);
            this._award = null;
            this._operBtn.dispose(param1);
            this._operBtn = null;
            this._state.dispose(param1);
            this._state = null;
            return;
        }// end function

    }
}
